package com.worker.microsoft.service.impl;

import com.onedec.admin.entity.OnedecEmp;
import com.onedec.admin.entity.OnedecEmpExample;
import com.worker.microsoft.mapper.OnedecEmpMapper;
import com.worker.microsoft.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private OnedecEmpMapper onedecEmpMapper;

    @Override
    public List<OnedecEmp> selectAll() {
        return onedecEmpMapper.selectByExample(null);
    }

    @Override
    public void insert(OnedecEmp onedecEmp) {
        onedecEmpMapper.insertSelective(onedecEmp);
    }

    @Override
    public OnedecEmp selectById(int id) {
        return onedecEmpMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(OnedecEmp onedecEmp) {
         onedecEmpMapper.updateByPrimaryKeySelective(onedecEmp);
    }

    @Override
    public OnedecEmp selectByFaceId(String empFaceid) {
        OnedecEmpExample onedecEmpExample = new OnedecEmpExample();
        OnedecEmpExample.Criteria or = onedecEmpExample.or();
        or.andEmpFaceidEqualTo(empFaceid);
        List<OnedecEmp> list = onedecEmpMapper.selectByExample(onedecEmpExample);
        if (list.size() != 0) {
            return list.get(0);
        }else{
            return null;
        }

    }

    public OnedecEmp findByUser(String empUsername) {
        return onedecEmpMapper.selectlogin(empUsername);
    }

    @Override
    public OnedecEmp findById(int empId) {
        OnedecEmp emp = onedecEmpMapper.selectByPrimaryKey(empId);
        return emp;
    }

    @Override
    public OnedecEmp findByEmail(String email) {
        OnedecEmp emp = onedecEmpMapper.selectEmail(email);
        return emp;
    }

    @Override
    public int updatePwd(OnedecEmp onedecEmp) {
        int i = onedecEmpMapper.updateByPrimaryKeySelective(onedecEmp);
        return i;
    }

    @Override
    public List<OnedecEmp> selectAllEmp() {
        List<OnedecEmp> list = onedecEmpMapper.selectByExample(null);
        return list;
    }

    public List<OnedecEmp> selectDesigner() {
        final OnedecEmpExample example = new OnedecEmpExample();
        example.createCriteria().andEmpRidEqualTo(3);
        final List<OnedecEmp> emps = onedecEmpMapper.selectByExample(example);
        return emps;
    }

    public List<OnedecEmp> selectManager() {
        final OnedecEmpExample example = new OnedecEmpExample();
        example.createCriteria().andEmpRidEqualTo(4);
        final List<OnedecEmp> emps = onedecEmpMapper.selectByExample(example);
        return emps;
    }

    public List<OnedecEmp> selectSupervision() {
        final OnedecEmpExample example = new OnedecEmpExample();
        example.createCriteria().andEmpRidEqualTo(5);
        final List<OnedecEmp> emps = onedecEmpMapper.selectByExample(example);
        return emps;
    }


}
